import request from '@/utils/request';
import axios from 'axios';

const API = {
    //获取学生请假的信息
    GET_LEAVES: 'v1/biz/leaves/all?',
    GET_LEAVE: 'v1/biz/leaves/one/',
    GET_STAY: 'v1/biz/leaves/dormitory/',
    POST_PICTURE: 'biz/Files/picture',
    GET_CLASSINFO: 'v1/biz/students/classInfo/',
    POST_SAVE: 'v1/biz/leaves/save',
    GET_LEAVEIMAGES: 'biz/Files/picture?id=',
    DELETE_LEAVE: 'v1//biz/leaves/save',
    GETDORM: 'v1/school/department/dorm',
    GETSTUDORMINFO: 'v1/school/class/dorm1?stuNum=',
    POST_DORMITORY: 'v1/biz/leaves/dormitory',
    //获取预约
    GET_RESERVE: 'v01/biz/appointments/listPsychology?',
    GETBULLETIN: 'v01/biz/inform/listInform?userNum=',
    GETBULLETIN_DETAIL: 'v01/biz/inform/informInfo?userNum=',
    /**
     * 以下为预约页面接口
     */
    // 心理预约记录老师端
    GETRESERBELIST: '/public/place/info/list?',
    PSYCHOLOGY_NOTE_IN_TEACHER_URL: '/public/place/info/list',
    // 查询心里预约
    INQUIRE_PSYCHOLOGY_NOTE_URL: '/v01/biz/appointments',
    // 老师端心理预约
    GET_TEACHER_PSY_NOTE_URL: '/v01/biz/appointments/listPsychology',
    // 获取老师心里预约详情
    GET_TEACHER_PSY_DETAIL_URL: '/v01/biz/appointments/psychologyInfo',
    // 撤销心理预约
    CANCEL_PSYCHOLOGY_NOTE_URL: '/v01/biz/appointments/delPsychology',
    // 获取所有心理老师预约的信息
    GET_PSY_TEACHER_DETAIL_URL:
        '/v01/biz/appointments/getAllAppointmentTeacher',
    // 上传心理预约
    UPDATE_PSY_NOTE_URL: '/v01/biz/appointments/updatePsychology',
    // 完成心理预约
    COMPLETE_PSY_NOTE_URL: '/v01/biz/appointments/setEndPsychology',
    // 获取心理预约老师的具体申请内容
    GET_PSY_TEACHER_APPLY_URL: '/v01/biz/appointments/teacherInfo',
    // 获取心理预约申请的离开时间
    GET_PSY_LEAVE_TIME_OPTION_URL: '/v01/biz/appointments/teacherLeaveTime',
    // 获取心理预约申请的成功时间
    GET_PSY_SUCCESS_TIME_OPTION_URL: '/v01/biz/appointments/getSuccessTimes',
    // 申请心理预约
    ADD_PSYCHOLOGY_NOTE_URL: '/v01/biz/appointments/savePsychology'
};

export const reqLeaveList = pN =>
    request.get(`${API.GET_LEAVES}pageNo=${pN}&pageSize=4`);

export const getleave = id => request.get(API.GET_LEAVE + id + '/');

export const getstay = id => request.get(API.GET_STAY + id + '/');

export const reqPicture = file => {
    const form = new FormData();
    form.append('file', file);
    return request.post(API.POST_PICTURE, form);
};

export const reqClassInfo = id => request.get(API.GET_CLASSINFO + id + '/');

export const reqSave = data => request.post(API.POST_SAVE, data);

export const reqLeaveImages = id =>
    request.get(API.GET_LEAVEIMAGES + id, {
        responseType: 'blob'
    });

export const reqDeleteLeave = data =>
    request.delete(API.DELETE_LEAVE, { data });

export const reqDorm = () => request.get(API.GETDORM);

export const reqStuDormInfo = stuNum =>
    request.get(API.GETSTUDORMINFO + stuNum);

export const reqDormitory = data => request.post(API.POST_DORMITORY, data);

export const reqLeaveMore = str => request.get(API.GET_LEAVES + str);

export const reqReserve = str => request.get(API.GET_RESERVE + str);
//获取公告列表(num为学号)
export const reqBulletin = num => request.get(API.GETBULLETIN + num);
//获取公告详细(num为学号, id为后端传的唯一id)
export const reqBulletinDetail = (num, id) =>
    request.get(API.GETBULLETIN_DETAIL + num + '&informId=' + id);

/**
 * 以下为预约接口
 */
export const reqReserveList = pN =>
    request.get(`${API.GETRESERBELIST}pageNo=${pN}&pageSize=4`);

export const reqPsychological = () =>
    axios.get('/public/json/psychologicalList.json');

export const savePsychology = data =>
    request.post('/public/json/savePsychology.json', data);
// 获取心理预约记录
export const reqPsychologyNote = (pageNo, pageSize = 5) =>
    request.get(
        `${API.PSYCHOLOGY_NOTE_URL}?pageNo=${pageNo}&pageSize=${pageSize}`
    );

// 获取心理预约记录代办
export const reqPsychologyNoteUntreated = (pageNo, pageSize = 5) =>
    request.get(
        `${API.PSYCHOLOGY_NOTE_URL}?state=0&pageNo=${pageNo}&pageSize=${pageSize}`
    );

// 获取心理预约记录已办
export const reqPsychologyNoteProcessed = (pageNo, pageSize = 5) =>
    request.get(
        `${API.PSYCHOLOGY_NOTE_URL}?state=23&pageNo=${pageNo}&pageSize=${pageSize}`
    );

// 查询心理预约
export const reqInquirePsychologyNote = (
    urlName,
    pageNo,
    pageSize = 5,
    states,
    startTime,
    endTime,
    userName
) =>
    request.get(
        `${API.INQUIRE_PSYCHOLOGY_NOTE_URL}/${urlName}?pageNo=${pageNo}&pageSize=${pageSize}&${states}&startTime=${startTime}&endTime=${endTime}&userName=${userName}`
    );

// 获取老师的心理预约
export const reqTeacherPSYNote = (pageNo, pageSize = 5) =>
    request.get(
        `${API.GET_TEACHER_PSY_NOTE_URL}?pageNo=${pageNo}&pageSize=${pageSize}&restrictState=0`
    );

// 查询老师端的心理预约
export const reqInquireTeacherPsychologyNote = (
    pageNo,
    pageSize = 5,
    state,
    restrictState
) =>
    request.get(
        `${API.GET_TEACHER_PSY_NOTE_URL}?pageNo=${pageNo}&pageSize=${pageSize}&state=${state}&restrictState=${restrictState}`
    );

// 老师端获取心理预约
export const reqPsychologyNoteInTeacher = (pageNo, pageSize) =>
    request.get(
        `${API.PSYCHOLOGY_NOTE_IN_TEACHER_URL}?pageNo=${pageNo}&pageSize=${pageSize}`
    );

// 获取老师心里预约详情
export const reqPsychologyNoteDetail = id =>
    request.get(`${API.GET_TEACHER_PSY_DETAIL_URL}?id=${id}`);

// 撤销心理预约
export const reqCancelPsychologyNote = id =>
    request.delete(`${API.CANCEL_PSYCHOLOGY_NOTE_URL}?id=${id}`);

// 获取所有心理老师预约的信息
export const reqAllTeacherDetail = () =>
    request.get(API.GET_PSY_TEACHER_DETAIL_URL);

// 上传心理预约
export const reqUpdatePsychologyNote = data =>
    request.put(API.UPDATE_PSY_NOTE_URL, data);

// 完成心理预约
export const reqCompletePsychologyNote = data =>
    request.put(API.COMPLETE_PSY_NOTE_URL, data);

// 获取心理预约老师申请具体内容
export const reqPsyTeacherApplyContent = id =>
    request.get(`${API.GET_PSY_TEACHER_APPLY_URL}?id=${id}`);

// 获取心理预约申请的离开时间
export const reqLeaveTime = id =>
    request.get(`${API.GET_PSY_LEAVE_TIME_OPTION_URL}?teacherNum=${id}`);

// 获取心理预约申请的成功时间
export const reqSuccessTime = (id, date) =>
    request.get(
        `${API.GET_PSY_SUCCESS_TIME_OPTION_URL}?teacherNum=${id}&date=${date}`
    );

// 申请心理预约
export const reqAddPsychologNote = data =>
    request.post(API.ADD_PSYCHOLOGY_NOTE_URL, data);
